package com.bh.web.controller.vehicle;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.vehicle.domain.JcVehicleHead;
import com.bh.vehicle.service.IJcVehicleHeadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车辆登记Controller
 * 
 * @author slx
 * @date 2023-11-26
 */
@RestController
@RequestMapping("/vehicle/vehicleHead")
public class JcVehicleHeadController extends BaseController
{
    @Autowired
    private IJcVehicleHeadService jcVehicleHeadService;

    /**
     * 查询车辆登记列表
     */
    @ApiOperation("查询车辆登记列表")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicleHead:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcVehicleHead jcVehicleHead)
    {
        startPage();
        List<JcVehicleHead> list = jcVehicleHeadService.selectJcVehicleHeadList(jcVehicleHead);
        return getDataTable(list);
    }


    /**
     * 查询车辆登记列表
     */
    @ApiOperation("查询车辆登记列表")
    @GetMapping("/searchList/{code}")
    public TableDataInfo searchList(@PathVariable String code)
    {
        JcVehicleHead jcVehicleHead = new JcVehicleHead();
        jcVehicleHead.setCode(code);
        startPage();
        List<JcVehicleHead> list = jcVehicleHeadService.selectJcVehicleHeadList(jcVehicleHead);
        return getDataTable(list);
    }


    /**
     * 查询目前车辆在出发地列表
     */
    @ApiOperation("查询目前车辆在出发地列表")
    @GetMapping("/searchVehicleExistList/{jcVehicleId}")
    public AjaxResult searchVehicleExistList(@PathVariable Long jcVehicleId)
    {
        List<JcVehicleHead> list = jcVehicleHeadService.selectVehicleExistList(jcVehicleId);
        return AjaxResult.success(list);
    }

    /**
     * 导出车辆登记列表
     */
    @PreAuthorize("@ss.hasPermi('vehicle:vehicleHead:export')")
    @Log(title = "车辆登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcVehicleHead jcVehicleHead)
    {
        List<JcVehicleHead> list = jcVehicleHeadService.selectJcVehicleHeadList(jcVehicleHead);
        ExcelUtil<JcVehicleHead> util = new ExcelUtil<JcVehicleHead>(JcVehicleHead.class);
        util.exportExcel(response, list, "车辆登记数据");
    }

    /**
     * 获取车辆登记详细信息
     */
    @ApiOperation("获取车辆登记详细信息")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicleHead:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcVehicleHeadService.selectJcVehicleHeadById(id));
    }

    /**
     * 新增车辆登记
     */
    @ApiOperation("新增车辆登记")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicleHead:add')")
    @Log(title = "车辆登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcVehicleHead jcVehicleHead)
    {
        return toAjax(jcVehicleHeadService.insertJcVehicleHead(jcVehicleHead));
    }

    /**
     * 修改车辆登记
     */
    @ApiOperation("修改车辆登记")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicleHead:edit')")
    @Log(title = "车辆登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcVehicleHead jcVehicleHead)
    {
        return toAjax(jcVehicleHeadService.updateJcVehicleHead(jcVehicleHead));
    }

    /**
     * 删除车辆登记
     */
    @ApiOperation("删除车辆登记")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicleHead:remove')")
    @Log(title = "车辆登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcVehicleHeadService.deleteJcVehicleHeadByIds(ids));
    }
}
